package com.ffdms.mobileoffice;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class BaseActivity extends Activity {

	@Override
	public void onBackPressed() {
		showExitDialog();
	}

	protected void showExitDialog() {
		AlertDialog.Builder builder = new Builder(this);
		builder.setMessage("确定要退出系统吗?");
		builder.setTitle("系统提醒");
		builder.setPositiveButton("确定",
				new android.content.DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						final SharedPreferences sp = getSharedPreferences(
								"login", Context.MODE_PRIVATE);
						Editor edi = sp.edit();
						edi.putString("Id", "");
						edi.putString("Password", "");
						edi.commit();
						dialog.dismiss();
						Intent startMain = new Intent(Intent.ACTION_MAIN);
						startMain.addCategory(Intent.CATEGORY_HOME);
						startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
						startActivity(startMain);
						System.exit(0);
					}
				});
		builder.setNegativeButton("取消",
				new android.content.DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				});
		builder.create().show();
	}
}
